-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add -g option to shield:user create
#1164
feat: add -g option to shield:user create
#1164
Conversation
$userModel->addToDefaultGroup($user); | ||
|
||
$this->write('The user is added to the default group.', 'green'); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if an invalid group is set?
shield:user create -n user1 -e [email protected] -g xxx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ ./spark shield:user create -n user2 -e [email protected] -g xxx
CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-08-20 04:13:43 UTC+00:00
Password : password
Password confirmation : password
User "user2" created
[CodeIgniter\Shield\Authorization\AuthorizationException]
xxx is not a valid group.
at VENDORPATH/codeigniter4/shield/src/Authorization/AuthorizationException.php:24
Backtrace:
1 VENDORPATH/codeigniter4/shield/src/Authorization/Traits/Authorizable.php:50
CodeIgniter\Shield\Authorization\AuthorizationException::forUnknownGroup('xxx')
2 VENDORPATH/codeigniter4/shield/src/Commands/User.php:324
CodeIgniter\Shield\Entities\User()->addGroup('xxx')
3 VENDORPATH/codeigniter4/shield/src/Commands/User.php:163
CodeIgniter\Shield\Commands\User()->create('user2', '[email protected]', 'xxx')
4 SYSTEMPATH/CLI/Commands.php:70
CodeIgniter\Shield\Commands\User()->run([...])
5 SYSTEMPATH/CLI/Console.php:48
CodeIgniter\CLI\Commands()->run('shield:user', [...])
6 SYSTEMPATH/Boot.php:351
CodeIgniter\CLI\Console()->run()
7 SYSTEMPATH/Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))
8 ROOTPATH/spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above is not good, but the same as addgroup
.
$ ./spark shield:user addgroup -n user1 -g mygroup
CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-08-20 04:12:13 UTC+00:00
Add the user "user1" to the group "mygroup" ? [y, n]: y
[CodeIgniter\Shield\Authorization\AuthorizationException]
mygroup is not a valid group.
at VENDORPATH/codeigniter4/shield/src/Authorization/AuthorizationException.php:24
Backtrace:
1 VENDORPATH/codeigniter4/shield/src/Authorization/Traits/Authorizable.php:50
CodeIgniter\Shield\Authorization\AuthorizationException::forUnknownGroup('mygroup')
2 VENDORPATH/codeigniter4/shield/src/Commands/User.php:600
CodeIgniter\Shield\Entities\User()->addGroup('mygroup')
3 VENDORPATH/codeigniter4/shield/src/Commands/User.php:195
CodeIgniter\Shield\Commands\User()->addgroup('mygroup', 'user1', null)
4 SYSTEMPATH/CLI/Commands.php:70
CodeIgniter\Shield\Commands\User()->run([...])
5 SYSTEMPATH/CLI/Console.php:48
CodeIgniter\CLI\Commands()->run('shield:user', [...])
6 SYSTEMPATH/Boot.php:351
CodeIgniter\CLI\Console()->run()
7 SYSTEMPATH/Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))
8 ROOTPATH/spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added checking the group name.
$ ./spark shield:user create -n user2 -e [email protected] -g xxx
CodeIgniter v4.5.4 Command Line Tool - Server Time: 2024-08-20 06:02:07 UTC+00:00
Password : password
Password confirmation : password
Invalid group: "xxx"
|
||
$this->write('The user is added to the default group.', 'green'); | ||
} else { | ||
$user->addGroup($group); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to be able to set up multiple groups. For example:
$user->addGroup('admin', 'beta');
shield:user create -n user1 -e [email protected] -g admin,beta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another enhancement.
If we add this, it is better to change all -g
option.
shield:user create -n newusername -e [email protected] -g mygroup
shield:user addgroup -n username -g mygroup
shield:user removegroup -n username -g mygroup
Lines 113 to 115 in a0fcea8
|
What do you think about adding interactions to show users a step-by-step guide. i created a similar command in a personal project to create a user like this. Complete the following form:
-----------------------------
User Name : Emilia
User Email : [email protected]
User Group : admin
New Password : 12345678
Confirm Password : 12345678
Account created!
----------------
Name Emilia
Email [email protected]
Group admin
Password 12345678
Done. |
c8a94c4
to
56662ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks.
Needs #1162Description
shield:user create
GroupModel::isValidGroup()
Checklist: